/*
 * Copyright (C) 2007 Evan Long    longx223 (at) umn (dot) edu
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/**
 * @file   framegrabber.h
 * @author Evan Long
 * 
 * @brief  Definition of frame_grabber_t which will be used to keep track of
 * our video4linux device that is being used to grab frames.
 * 
 * 
 */

#ifndef FRAMEGRABBER_H
#define FRAMEGRABBER_H

/**
 * Stores information about a video4linux device as well as a buffer for an 
 * image to be stored in. 
 * 
 * @param device Full path to the device that will be used to acquire images.
 * @param devfd File descripter to the device that is opened.
 * @param width Maximum width that is supported by the device.
 * @param height Maximum height that is supported by the device.
 * @param bufsize 3*width*height because there are 3 bytes per pixel.
 * @param buffer Pointer to the buffer allocated for an image.
 */
typedef struct frame_grabber
{
  char* device;
  int devfd;
  int width;
  int height;
  int bufsize;
  unsigned char* buffer;
} frame_grabber_t;

/** 
 * Initialize a device that will be used to read frames access frames for the
 * user. 
 *
 * @param device Full path to the device that will be associated with this 
 * instance of frame_grabber_t.
 * 
 * @return Pointer to a new instance of frame_grabber_t.
 */
frame_grabber_t* new_frame_grabber(const char* device);

/** 
 * Grab a frame from the device. Return NULL if the frame could not be grabbed.
 * 
 * @param fgt Instance of frame_grabber_t where the image will be grabbed from.
 * 
 * @return Pointer to the buffer
 */
unsigned char* grab_frame(frame_grabber_t* fgt);

/** 
 * Free all memory associated an instance of frame_grabber_t.
 * 
 * @param fgt Instance of frame_grabber_t.
 */
void free_frame_grabber(frame_grabber_t* fgt);

#endif
